package jaran.Tomxk.reflect_practice_2;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class AppCore {
    public static void main(String[] args) throws Exception{
        Class<?> A = Class.forName("jaran.Tomxk.reflect_practice_2.CoreService");
        Object o = A.newInstance();
        Field[] fields = A.getDeclaredFields();


        for (Field field : fields){
            field.setAccessible(true);
            Class<?> type = field.getType();
//            if(type.toString().endsWith("CustomerService")){
//                Class<?> B = Class.forName("jaran.Tomxk.reflect_practice_2.CustomerService");
//                field.set(o,B.newInstance());
//            }
//            if(type.toString().endsWith("OrderService")){
//                Class<?> C = Class.forName("jaran.Tomxk.reflect_practice_2.OrderService");
//                field.set(o,C.newInstance());
//            }
//            if(type.toString().endsWith("UserService")){
//                Class<?> D = Class.forName("jaran.Tomxk.reflect_practice_2.UserService");
//                field.set(o,D.newInstance());
//            }
            Object u = type.newInstance();
            field.set(o,u);
        }


        Method say = A.getDeclaredMethod("say");
        say.invoke(o);

    }
}
